from datetime import datetime


def time_to_str(time_, time_format='%Y-%m-%d %H:%M:%S'):
    return time_.strftime(time_format)


def now_to_str(time_format='%Y-%m-%d %H:%M:%S'):
    return datetime.now().strftime(time_format)


def time_to_str_ms(time_):
    # 获取当前时间

    # 格式化输出带有毫秒的当前时间字符串
    current_time_str = time_.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
    return current_time_str


def now_to_str_ms():
    return datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]


def str_to_time(time_str, time_format='%Y-%m-%d %H:%M:%S'):
    return datetime.strptime(time_str, time_format)


def date_to_str(date_value, time_format='%Y-%m-%d'):
    return date_value.strftime(time_format)


def today_to_str(time_format='%Y-%m-%d'):
    return date_to_str(datetime.now(), time_format)


def str_to_date(date_str, date_format='%Y-%m-%d'):
    return str_to_time(date_str, date_format)
